package com.googlecode.roleaccesscontrol.entity;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotBlank;

@Entity(name = "ROLE")
public class Role implements Serializable {

	@Id
	@GeneratedValue
	private Long id;

	@NotNull
	private Boolean active;

	@NotBlank
	@Size(max = 128)
	private String name;

	@NotBlank
	@Size(max = 255)
	private String description;

	@ManyToMany(cascade = CascadeType.ALL, mappedBy = "roles", targetEntity = Profile.class)
	private Collection<Profile> profiles;

	@NotNull
	@ManyToOne
	@JoinColumn(name = "APPLICATION_ID")
	private Application application;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Boolean getActive() {
		return active;
	}

	public void setActive(Boolean active) {
		this.active = active;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Collection<Profile> getProfiles() {
		return profiles;
	}

	public void setProfiles(Collection<Profile> profiles) {
		this.profiles = profiles;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	@Override
	public String toString() {
		return name;
	}
}
